package com.zty.schedule.api;

import com.zty.schedule.entity.Plan;
import com.zty.schedule.entity.PlanTree;
import com.zty.schedule.entity.Value;
import com.zty.schedule.entity.ValueRecord;
import com.zty.schedule.service.PlanService;
import com.zty.schedule.service.ValueRecordService;
import com.zty.schedule.service.ValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;

@Api(description = "统计接口")
@RestController
@RequestMapping("Statistics")
@CrossOrigin
public class StatisticsController {
    @Autowired
    private PlanService planService;

    @Autowired
    private ValueService valueService;

    @Autowired
    private ValueRecordService valueRecordService;


    @ApiOperation(value = "进度对比",notes = "")
    @PostMapping("/Comparison")
    public List Comparison(){
        List<Plan> plans= planService.Comparison();
        List list = new ArrayList();
        for (int i=0;i<plans.size();i++){
            PlanTree planTree = new PlanTree();
            String s=null;
            s="["+plans.get(i).getStart_day()+","+plans.get(i).getEnd_day()+"]";

            String z=null;
            z="["+plans.get(i).getStart_day()+","+(plans.get(i).getStart_day()+plans.get(i).getPractical_day())+"]";

            char[] z1=z.toCharArray();
            char[] s1=s.toCharArray();
            //System.out.println(z1);
            //System.out.println(s1);
            planTree.setId(plans.get(i).getId());
            planTree.setName(plans.get(i).getName());
            planTree.setStart_time(plans.get(i).getStart_time());
            planTree.setStart_day(plans.get(i).getStart_day());
            planTree.setEnd_time(plans.get(i).getEnd_time());
            planTree.setEnd_day(plans.get(i).getEnd_day());
            planTree.setPlan_day(plans.get(i).getPlan_day());
            planTree.setPractical_day(plans.get(i).getPractical_day());
            planTree.setPractical_time(plans.get(i).getPractical_time());
            planTree.setState(plans.get(i).getState());
            planTree.setJihua(s1);
            planTree.setShiji(z1);
            list.add(planTree);
        }

        return list ;
    }

    @ApiOperation(value = "进度分析", notes = "")
    @PostMapping("/Analyse")
    public List<Plan> Analyse(){
        return planService.Analyse();
    }

    @ApiOperation(value = "总产值",notes = "")
    @PostMapping("/FindValue")
    public Double FindValue(){
        Value value = valueService.FindValue();
        Double d = value.getAltogether();
        return d;
    }

    @ApiOperation(value = "累计产值",notes = "")
    @PostMapping("/SumValue")
    public BigDecimal SumValue(){
        ValueRecord valueRecord =valueRecordService.SumValue();
        Double d=valueRecord.getCount();
        System.out.println(d);
        BigDecimal a =new BigDecimal(d.toString());
        System.out.println(a.doubleValue());
        return a;
    }

    @ApiOperation(value = "产值分析",notes = "")
    @PostMapping("/CountValue")
    public List<ValueRecord> CountValue(){
        return valueRecordService.CountValue();
    }
}
